#include "empty.h"

#ifndef __PID_H
#define __PID_H


typedef enum {
    OPEN_LOOP = 0,
    GRAYSCALE = 1,
	GRAYSCALE_TURN = 2,
    ANGLE_Left = 3,
	ANGLE_Right = 4,
    SPEED = 5,
    POSITION = 6,
    SPEED_POSITION_DUAL_LOOP = 7
} PID_Mode;


typedef struct
{
	float yaw;
	float speed;
	int leftPulse;
	int rightPulse;
}TARGET_typeDef;


typedef struct
{
	float Kp;
	float Ki;
	float Kd;
	float Ur;							//限幅值
	float Ur_d;							//下限限幅值
	float Ur_i;     					//积分限幅系数
	float U_en;							//允许误差
	
	uint8_t PID_is_Enable;				//PID使能
	int Un;								//期望输出值
	float En_1;							//上一次误差
	float En_2;							//上上次误差
	float En_All;						//累积误差
	int PWM;							//输出PWM值ֵ

	uint8_t state;						//状态
	
}PID_InitDefStruct;

/* value of PID */


void PIDCal_Start(void);
void PIDCal_End(void);

//int PID_Velocity(float TargetVelocity, float CurrentVelocity, PID_InitDefStruct* p);
//int PID_Position(int TargetCul, int CurrentCul, PID_InitDefStruct* p);

int PID_Angle_1(float angle,float balance_angle, int Gyro, PID_InitDefStruct* p);
int PID_Angle_2(float angle,float balance_angle, PID_InitDefStruct* p);
//int PID_Veer(float encoder_left, float encoder_right, int Gyro, PID_InitDefStruct* p);

int PID_GrayScale(PID_InitDefStruct* p);

//int PID_Steer(float Angle, float TargetAngle, int Gyro, PID_InitDefStruct* p);
//int PID_Steer_Incremental(float Angle, float TargetAngle, PID_InitDefStruct* p);
//int PID_Steer_Follow(float Coord, float Target_Coord, 
//					 float Distance, PID_InitDefStruct* p);

//int PID_Pos_Vel(int TargetC,int CurrentC,PID_InitDefStruct* Pp,
//				int CurrentV,PID_InitDefStruct* Pv);

void PID_ModeChoose(PID_Mode mode);



#endif
